/**
@file
@brief A software timer to count time and do something at speific time.
@details As many tasks require a timer to know the time, but the hardware 
         timer resource is limited, so it's a covenient way to design a software
         timer to share a single hardware timer, which is Systick.
         
         All the SoftTimer should be registered into a list, and they 
         are ieterated in the Systick Handler. A SoftTimer counts from 0 to 
         final_val, and then restarts from 0. When it hits the final_val, it
         invokes a callback functions. This behaves pretty like Systick.
         
         The interval of SortTimer's two count is 10 us (i.e. the clock of this timer).
         
         
         Example usage:
         void do_nothing(void) { }
         
         int main(void) {
            SoftTimer_TypeDef sft;
            
            SfTim_InitSys();
            SfTim_Init(&sft, 1000, do_nothing);
         }
         
         void Systick_IRQHandler(void) {
            SfTim_CountAll();
         }
*/


#ifndef SOFT_TIMER_H__
#define SOFT_TIMER_H__
#include "board.h"
#include "stdint.h"


typedef struct {
    bool enabled;
    uint32_t cnt;
    uint32_t final_val;
    
    void (*callback)(void);
} SoftTimer_TypeDef;


void SfTim_InitSys(void);
bool SfTim_Init(SoftTimer_TypeDef *sft, uint32_t final_val, void(*cb)());
void SfTim_Enable(SoftTimer_TypeDef *sft);
void SfTim_Disable(SoftTimer_TypeDef *sft);
void SfTim_CountAll(void);


#endif  // SOFT_TIMER_H__
